//
//  HomeRoomCell.m
//  AILock
//
//  Created by 谭亚明 on 2020/6/24.
//  Copyright © 2020 tym. All rights reserved.
//

#import "HomeRoomCell.h"
#import "UIImageView+YPImage.h"

@interface HomeRoomCell()

@property(nonatomic,weak) IBOutlet UIView *conView;

@property(nonatomic,copy) NSMutableArray *imageArray;
@end

@implementation HomeRoomCell

- (void)awakeFromNib {
    
    [super awakeFromNib];
    

    
    self.conView.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
    self.conView.layer.cornerRadius = 10;
}

-(NSMutableArray*)imageArray{
    if (_imageArray == nil) {
        _imageArray = [[NSMutableArray alloc] init];
    }
    return _imageArray;
}

+(CGFloat)cellForHeight{
    return 86;
}

+(NSString*)identifier{
    return @"HomeRoomCell";
}

-(void)setRoomModel:(RoomModel *)roomModel{
    _roomModel = roomModel;
    _roomName.text = roomModel.roomName;
    _equmentCountLab.text = [NSString stringWithFormat:@"%ld个设备",roomModel.count];
    
    for (UIView *view in self.contentView.subviews.firstObject.subviews) {
        if ([view isKindOfClass:[UIImageView class]] && view.frame.size.height == 40) {
            [view removeFromSuperview];
        }
    }

    float allWith = roomModel.familyEquipmentDataList.count * 50;
    for(int i=0;i<roomModel.familyEquipmentDataList.count;i++){
        EquipmentModel *equMode = roomModel.familyEquipmentDataList[i];
        UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(i*50 + (ScreenWidth - 30) - allWith - 28 - 10, 15.5, 40, 40)];
        view.contentMode = UIViewContentModeScaleAspectFill;
        [view yp_setImageUlr:[equMode getEquipmentImage]];
        [self.conView addSubview:view];
    }
}


@end
